home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6821 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  55 lines

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: trouble with command line args, need help
  5. Date: 19 Feb 1996 23:58:18 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4gb2qq$197@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe15.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Feb 18, 1996 21:20:56 in article <trouble with command line args, need
  15. help>, 'thecrow@iconn.net (The Crow)' wrote: 
  16.  
  17.  
  18. >Hey, I have a program that has three strings defined as such 
  19. >char key[80]; 
  20. >char ifn[12]; 
  21. >char ed[1]; 
  22. >Then I read in the command line arguments in the main function like so: 
  23. >main(int argc, char* argv[])  { 
  24. >blablabla 
  25. >} 
  26. >then inside the main function I try to do this 
  27. >ifn = argv[1]; 
  28. >ed = argv[2]; 
  29. >key = argv[3]; 
  30. The C++ way: 
  31.  
  32. #include <strstrea.h>  (MSVC++4.0 name) 
  33.  
  34.     ostrstream os(key, 80); 
  35.     os << argv[1] << ends; 
  36. - - - - - - - 
  37. The C way: 
  38. #include <string.h> 
  39.  
  40.    strcpy(key, argv[1); 
  41.  
  42. While the C++ way is safe, C is not -- you should make 
  43. sure that the receiving string is large enough. 
  44.  
  45. -- 
  46. Pete Grant 
  47. Kalevi, Inc. 
  48. Software Engineering & development
  49.